home *** CD-ROM | disk | FTP | other *** search
- // VarSelectDlg.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "VarSelectDlg.h"
- #include "DvDsDll.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
-
- BOOL CVarSelectDlg::m_FirstTime = TRUE;
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CVarSelectDlg dialog
-
-
- CVarSelectDlg::CVarSelectDlg(VARDEFDATA* pList, DV_DSDLLDATA* m_pData, CWnd* pParent /*=NULL*/)
- : CDialog(CVarSelectDlg::IDD, pParent), m_pVarDefList(pList),m_pData(m_pData),
- m_pSelectedVarData(0)
- {
- //{{AFX_DATA_INIT(CVarSelectDlg)
- //}}AFX_DATA_INIT
- }
-
-
- void CVarSelectDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CVarSelectDlg)
- DDX_Control(pDX, IDC_VARLIST, m_VarList);
- //}}AFX_DATA_MAP
- }
-
-
- BEGIN_MESSAGE_MAP(CVarSelectDlg, CDialog)
- //{{AFX_MSG_MAP(CVarSelectDlg)
- ON_BN_CLICKED(IDC_STD_BROWSER, OnStdBrowser)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CVarSelectDlg message handlers
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- BOOL CVarSelectDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- int nIndex;
- CString colVal;
- VARDEFDATA* pList;
- CRect r;
-
- m_VarList.GetClientRect(&r);
- int width = r.right/10;
- int nigglybits = r.right % 10;
-
- VERIFY(m_StdBrowser.AutoLoad(IDC_STD_BROWSER, this));
-
- m_VarList.InsertColumn(0,"Variable", LVCFMT_LEFT, 3*width);
- m_VarList.InsertColumn(1,"Type", LVCFMT_LEFT, 2*width,1);
- m_VarList.InsertColumn(2,"Min", LVCFMT_CENTER, width,2);
- m_VarList.InsertColumn(3,"Max", LVCFMT_CENTER, width,3);
- m_VarList.InsertColumn(4,"Shape", LVCFMT_LEFT, (3*width+nigglybits),4);
-
- for(nIndex = 0,pList = m_pVarDefList;pList;pList = pList->next,nIndex++)
- {
- m_VarList.InsertItem(nIndex,(LPCTSTR)pList->m_csVarName.SpanExcluding(";"));
- m_VarList.SetItemData(nIndex, (DWORD)pList);
-
- m_VarList.SetItemText(nIndex, 1, (LPCTSTR)pList->m_csVarTypeName);
-
- colVal.Format("%.3g",pList->m_dLowRange);
- m_VarList.SetItemText(nIndex, 2, (LPCTSTR)colVal);
- colVal.Format("%.3g",pList->m_dHighRange);
- m_VarList.SetItemText(nIndex, 3, (LPCTSTR)colVal);
-
- // Determine something useful to say about the variables shape...
- if(pList->m_nCols == 1)
- {
- if(pList->m_nRows == 1)
- colVal = "SCALAR";
- else
- colVal.Format("COL. VECTOR[%d][%d]",pList->m_nRows,pList->m_nCols);
- }
- else if(pList->m_nRows == 1)
- colVal.Format("ROW VECTOR[%d][%d]",pList->m_nRows,pList->m_nCols);
- else
- colVal.Format("MATRIX[%d][%d]",pList->m_nRows,pList->m_nCols);
-
- m_VarList.SetItemText(nIndex, 4, (LPCTSTR)colVal);
- }
-
- // Just a little cutsie example of how a data source DLL can discriminate
- // accurately the various contexts from which it is being called from within
- // the core of DV-Draw...
-
- CString context;
-
- if(m_pData->m_Context & DV_DSDLL_SELECTDATA)
- context = "Select new variable for ";
- else
- context = "Changing variable in ";
-
- if(m_pData->m_Context & DV_DSDLL_EDITDYNAMICS)
- context += "DYNAMICS";
- else if(m_pData->m_Context & DV_DSDLL_EDITGRAPH)
- context += "GRAPH";
- else if(m_pData->m_Context & DV_DSDLL_EDITINPUT)
- context += "INPUT OBJECT";
- else
- context += "!!! UNKNOWN !!!";
-
- SetWindowText((LPCTSTR)context);
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- // Called by the list conrol, which does hit testing for us...
- //
- void CVarSelectDlg::SelectItem(int nItem)
- {
- m_pSelectedVarData = (VARDEFDATA*)m_VarList.GetItemData(nItem);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- void CVarSelectDlg::OnStdBrowser()
- {
- CDvDsDll* pDsDll;
-
- DVIGetInterface(IID_DV_Datasource, (void**)&pDsDll);
-
- if(!pDsDll)
- {
- AfxMessageBox("Unable to load standard DataViews Data Browser!");
- return;
- }
-
- if(m_FirstTime)
- {
- // Our data browser does not work with the view directly, so there are
- // no default datasources created when the view is initialized. For
- // our purposes here as an example, if its the first time, we'll ask the
- // standard data browser to init the view; that way there will be some-
- // thing to see (otherwise its an empty datasource list).
- int real_context = m_pData->m_Context;
-
- m_pData->m_Context = DV_DSDLL_INITNEWVIEW;
- pDsDll->HandleRequest(m_pData,this);
- m_pData->m_Context = real_context;
-
- m_FirstTime = FALSE;
- }
-
- if(((pDsDll->HandleRequest(m_pData,this)) == IDOK) )
- {
- // User has selected OK button, so we could do some application
- // specific things at this point. The assignment below is merely
- // a convenient place for stopping the debugger so you can see what
- // is happening.
- DSVAR newDsvar = m_pData->m_DsVar;
- }
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- void CVarSelectDlg::OnOK()
- {
- // Is variable selection required?
- BOOL needVAR = (BOOL)((m_pData->m_Context & DV_DSDLL_SELECTDATA) ||
- (m_pData->m_Context & DV_DSDLL_EXCHANGEDATA) );
-
- if(!needVAR || (needVAR && m_pSelectedVarData))
- CDialog::OnOK();
- else
- Beep(300,150);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- void CVarSelectDlg::OnCancel()
- {
- m_pSelectedVarData = 0;
- CDialog::OnCancel();
- }
-
-